package tech.aistar.service.order.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tech.aistar.dao.IServicesDao;
import tech.aistar.entity.ServiceOrder;
import tech.aistar.entity.Services;
import tech.aistar.mapper.order.ServiceOrderMapper;
import tech.aistar.service.order.IServiceOrderService;
import tech.aistar.vo.ServiceOrderVo;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by 23827 on 2019/9/28.
 */
@Service
public class ServiceOrderServiceImpl implements IServiceOrderService {
    @Autowired
    private ServiceOrderMapper serviceOrderMapper;
    @Autowired
    private IServicesDao iServicesDao;
    @Override
    public List<ServiceOrder> findAll() {
        List<ServiceOrder> list = serviceOrderMapper.findAll();
        return list;
    }

    @Override
    public List<ServiceOrder> find(String order_number) {
        List<ServiceOrder> list2 = serviceOrderMapper.find(order_number);

        return list2;
    }

    @Override
    public ServiceOrder delById(Integer id) {
        serviceOrderMapper.delById(id);


        return null;
    }

    @Override
    public ServiceOrder insertServiceOrder(ServiceOrder serviceOrder) {
        serviceOrderMapper.insertServiceOrder(serviceOrder);

        return serviceOrder;
    }

    @Override
    public ServiceOrder updateServiceOrder(ServiceOrder serviceOrder) {
        serviceOrderMapper.updateServiceOrder(serviceOrder);

        return serviceOrder;
    }

    @Override
    public List<ServiceOrder> getById(Integer id) {
        List<ServiceOrder> list3 = serviceOrderMapper.getById(id);
        return list3;
    }

    @Override
    public ServiceOrder findByIdOne(Integer id) {
        ServiceOrder serviceOrder = serviceOrderMapper.findByIdOne(id);
        return serviceOrder;
    }

    //服务订单表的第三方实体类
    @Override
    public List<ServiceOrderVo> serviceOrderVo(Integer userinfo_id) {
        List<Services> servicesList = iServicesDao.findAll();
//        List<ServiceOrder> serviceOrderList = serviceOrderMapper.findAll();
        List<ServiceOrder> serviceOrderList = serviceOrderMapper.findByUserinfoId(userinfo_id);
        List<ServiceOrderVo> serviceOrderVoList = new ArrayList<>();
        for (int i = 0; i <serviceOrderList.size() ; i++) {
            ServiceOrderVo svo = new ServiceOrderVo();
            Services s = servicesList.get(i);
            ServiceOrder so = serviceOrderList.get(i);
//            svo.setServices(s);
            //获取到服务订单表中的id
            Integer id = so.getId();
            svo.setId(id);
            //获取到服务订单表中的订单编号
            String orderNumber = so.getOrderNumber();
            svo.setOrderNumber(orderNumber);
            //获取服务表中的服务名称

            Services services = iServicesDao.findById(so.getServicesId()).get();
            String title = services.getTitle();
            svo.setTitle(title);
            //获取到服务表中的服务介绍
            String intro = s.getIntro();
            svo.setIntro(intro);
            //获取服务表中放入服务总价格
            Double total = so.getTotal();
            svo.setTotal(total);
            //获取服务订单表中的时间
            Date commitTime = so.getCommitTime();
            svo.setCommitTime(commitTime);
            //获取服务订单表中的状态
            Integer status = so.getStatus();
            svo.setStatus(status);

            serviceOrderVoList.add(svo);

        }
        return serviceOrderVoList;
    }

    @Override
    public Integer findByOrderNumber(String order_number) {
        Integer serviceOrder = serviceOrderMapper.findByOrderNumber(order_number);
        return serviceOrder;
    }

    @Override
    public String selectById(Integer id) {
        String orderNumber = serviceOrderMapper.selectById(id);
        return orderNumber;
    }

    @Override
    public void updateOne(ServiceOrder serviceOrder) {
        serviceOrderMapper.updateOne(serviceOrder);
    }

//    @Override
//    public ServiceOrder selectById(Integer id) {
//        ServiceOrder serviceOrder = serviceOrderMapper.selectById(id);
//        return serviceOrder;
//    }
}
